$(function() {
	$('#vue_vm_list div').hide();
});

var foodMealsApply = {
	foodMealsApplyId: '',
	relationId: '',
	relationName: '',
	relationCardId: '',
	relationType: '',
	approveStatus: '',
	createTime: '',
	updateTime: '',
	createId: getLoginedUser()? getLoginedUser().staffId: '',
	updateId: getLoginedUser()? getLoginedUser().staffId: '',
	foodMealsId: '',
	applyDate: '',
};

var view = {
	data: foodMealsApply
};

if($('#vue_vm').length > 0) {
	var vue_vm = new Vue({
		el: '#vue_vm',
		data: view
	});
}

foodMealsApply_findAll();

function save() {
	view.data.relationType = (view.data.relationType==''? 0: parseInt(view.data.relationType));
	view.data.approveStatus = (view.data.approveStatus==''? 0: parseInt(view.data.approveStatus));

	save_basic(path+'/foodMealsApply/save', {foodMealsApply:view.data}, function() {
		findAll();
	});
}

function foodMealsApply_findAll() {
	if($('#vue_vm_list div').length==0) {return;}
	$('#vue_vm_list div').hide();

	findAll_basic(path+'/foodMealsApply/findAll', function(response) {
		$('#vue_vm_list').html(gl_vue_vm_list_html);
		
		for(var i=0; i<response.data.length; i++) {
			response.data[i].index = i+1;
		}
		
		new Vue({
			el: '#vue_vm_list',
			data: {
				todos: response.data
			},
			methods: {
				getSubsidizationValue:function(subsidization, subsidizationValue) {
					return getSubsidizationValue(subsidization, subsidizationValue);
				},
				getSubsidizationUnit:function(subsidization) {
					return getSubsidizationUnit(subsidization);
				},
				getSubsidizationText:function(subsidization, subsidizationValue) {
					return getSubsidizationText(subsidization, subsidizationValue);
				},
				getConsDeductionText:function(consumptionWay, consDeductionWay) {
					return getConsDeductionText(consumptionWay, consDeductionWay);
				},
				//总共可扣月数
				getTotalMonths:function(todo) {
					return getTotalMonths(todo);
				},
				//剩余可扣月数
				getRemainMonths:function(todo) {
					return getRemainMonths(todo);
				},
				//已扣月数
				getAlreadyUsedMonths:function(todo) {
					return getAlreadyUsedMonths(todo);
				},
				//总共可扣天数
				getTotalNumber:function(todo) {
					return getTotalNumber(todo);
				},
				//剩余可扣天数
				getRemainNumber:function(todo) {
					return getRemainNumber(todo);
				},
				//已扣天数
				getAlreadyUsedNumber:function(todo) {
					return getAlreadyUsedNumber(todo);
				},
				
				foodMealsApply_approve_ok:function(todo) {
					if(confirm('确实要通过吗？')) {
						save_basic_by_json(path+'/foodMealsApply/approve', {id:todo.foodMealsApplyId, approveStatus:1}, function() {
							$('#'+todo.foodMealsApplyId+'_div').remove();
							todo.approveStatus = 1;
							alert('通过成功');
						});
					}
				},
				foodMealsApply_approve_deny:function(todo) {
					if(confirm('确实要拒绝吗？')) {
						save_basic_by_json(path+'/foodMealsApply/approve', {id:todo.foodMealsApplyId, approveStatus:2}, function() {
							$('#'+todo.foodMealsApplyId+'_div').remove();
							todo.approveStatus = 2;
							alert('拒绝成功');
						});
					}
				}
			}
		});
		
		$('#vue_vm_list div').show();
	});
}

function deleteBatch() {
	deleteBatch_basic(path+'/foodMealsApply/deleteBatch');
}
